#------------------------------------------------------------------------------
# Top-level CMake file for cpp-ethereum.
#
# The documentation for cpp-ethereum is hosted at http://cpp-ethereum.org
#
# ------------------------------------------------------------------------------
# This file is part of cpp-ethereum.
#
# cpp-ethereum is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cpp-ethereum is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cpp-ethereum.  If not, see <http://www.gnu.org/licenses/>
#
# (c) 2014-2016 cpp-ethereum contributors.
#------------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.0.0)

set(ETH_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake" CACHE PATH "The path to the cmake directory")
list(APPEND CMAKE_MODULE_PATH ${ETH_CMAKE_DIR})

set(CPP_ETHEREUM_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path to the root directory for cpp-ethereum")

# set cmake_policies
include(EthPolicy)
eth_policy()

# project name and version should be set after cmake_policy CMP0048
project(cpp-ethereum VERSION "1.3.0")

include(EthCompilerSettings)
include(EthExecutableHelper)
include(EthDependencies)
include(EthUtils)
include(EthOptions)


find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)
message("json libraries:" ${JSONCPP_LIBRARIES})
link_libraries(${JSONCPP_LIBRARIES})
# target_link_libraries(cpp-ethereum ${JSONCPP_LIBRARIES})


if(JSONCPP_FOUND)
    message("INFO: we found LibJsoncpp on your pc.")
    message(Jsoncpp_FOUND = ${JSONCPP_FOUND})
    message(Jsoncpp_INCLUDE_DIR = ${JSONCPP_INCLUDE_DIR}) 
    message(Jsoncpp_INCLUDE_DIRS = ${JSONCPP_INCLUDE_DIRS}) 
    message(Jsoncpp_LIBRARY = ${JSONCPP_LIBRARY})
else(JSONCPP_FOUND)
    message("ERROR: we couldn't find LibJsoncpp on your pc")
endif(JSONCPP_FOUND)

include(deps/jsonrpc.cmake)
include(cmake/Findjson_rpc_cpp.cmake)
message(  "JSON_RCP_CPP_INCLUDE_DIRS:"    ${JSON_RCP_CPP_INCLUDE_DIRS})
message(  "JSON_RCP_CPP_LIBRARIES:"        ${JSON_RCP_CPP_LIBRARIES})
message(  "JSON_RPC_CPP_SERVER_LIBRARIES:" ${JSON_RPC_CPP_SERVER_LIBRARIES})
message(  "JSON_RPC_CPP_CLIENT_LIBRARIES:" ${JSON_RPC_CPP_CLIENT_LIBRARIES})
message(  "JSON_RCP_CPP_FOUND:"            ${JSON_RCP_CPP_FOUND})
message(  "JSON_RPC_CPP_VERSION:"          ${JSON_RPC_CPP_VERSION})
message(  "JSON_RPC_CPP_VERSION_MAJOR:"    ${JSON_RPC_CPP_VERSION_MAJOR})
message(  "JSON_RPC_CPP_VERSION_MINOR:"    ${JSON_RPC_CPP_VERSION_MINOR})
message(  "JSON_RPC_CPP_VERSION_PATCH:"  ${JSON_RPC_CPP_VERSION_PATCH})

configure_project(CPUID CURL ETHASHCL EVMJIT FATDB MINIUPNPC ROCKSDB PARANOID TESTS VMTRACE)

add_subdirectory(eth)
add_subdirectory(libdevcore)
add_subdirectory(libdevcrypto)
add_subdirectory(libethash)
add_subdirectory(libethashseal)
add_subdirectory(libethcore)
add_subdirectory(libethereum)
add_subdirectory(libevm)
add_subdirectory(libevmcore)
if (NOT EMSCRIPTEN)
    add_subdirectory(libp2p)
endif()

add_subdirectory(libweb3jsonrpc)
add_subdirectory(libwebthree)
add_subdirectory(libwhisper)

if (ETHASHCL)
    add_subdirectory(libethash-cl)
endif()

if (EVMJIT)
 message("we're doing EVMJIT")
	include(deps/evmjit.cmake)

if(EVMJIT_FOUND)
 message("and we found EVMJIT!")
endif()

endif()

if (TOOLS)
    add_subdirectory(ethkey)
    add_subdirectory(ethminer)
    add_subdirectory(ethvm)
    if (NOT EMSCRIPTEN)
        add_subdirectory(rlp)
        add_subdirectory(bench)
    endif()
endif()

if (TESTS)
	add_subdirectory(test)
endif()

# TODO - split out json_spirit, libscrypt and sec256k1
add_subdirectory(utils)

#add_compile_options(-pthreads)
#find_package(Threads)
